package com.atguigu.paymentdemo.controller;

import com.atguigu.common.utils.R;
import com.atguigu.paymentdemo.entity.Product;
import com.atguigu.paymentdemo.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin  //开放前端跨域访问
@RestController
@RequestMapping("/api/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/test")
    public R test() {
        return R.ok();
    }

    @GetMapping("/list")
    public R productList() {
        List<Product> list = productService.list();
        return R.ok().put("productList", list);
    }

}
